//
//  SearchHistoryCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/6.
//

import UIKit

class SearchHistoryCell: UITableViewCell {
    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 14)
        label.textColor = .init(named: "gray_666666")
        return label
    }()
    
    lazy var deleteBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage(UIImage(named: "ico_clised"), for: .normal)
        btn.rx.tap.bind { [weak self] in
            self?.deleteClosure?()
        }.disposed(by: rx.disposeBag)
        return btn
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = .init(named: "gray_D0D0D0")
        return view
    }()
  
    var deleteClosure: ReturnClosure?

    var model: String? {
        didSet {
            nameLabel.text = model
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        contentView.addSubview(nameLabel)
        contentView.addSubview(deleteBtn)
        contentView.addSubview(lineView)
        nameLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(12)
            make.width.lessThanOrEqualTo(scaleWidth(300))
        }
        deleteBtn.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(-26)
            make.height.width.equalTo(16)
        }
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(12)
            make.bottom.equalTo(0)
            make.right.equalTo(-12)
            make.height.equalTo(0.5)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
